home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 10868 / 10868.xpi / chrome / sync.jar / content / notification.xml < prev    next >
Extensible Markup Language  |  2010-02-02  |  6KB  |  158 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE bindings [
  4. <!ENTITY % notificationDTD SYSTEM "chrome://global/locale/notification.dtd">
  5. %notificationDTD;
  6. <!ENTITY % weaveNotificationDTD SYSTEM "chrome://weave/locale/notification.dtd">
  7. %weaveNotificationDTD;
  8. ]>
  9.  
  10. <bindings id="notificationBindings"
  11.           xmlns="http://www.mozilla.org/xbl"
  12.           xmlns:xbl="http://www.mozilla.org/xbl"
  13.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  14.  
  15.   <binding id="notificationbox" extends="chrome://global/content/bindings/notification.xml#notificationbox">
  16.     <content>
  17.       <xul:vbox xbl:inherits="hidden=notificationshidden">
  18.         <xul:spacer/>
  19.         <children includes="notification"/>
  20.       </xul:vbox>
  21.       <children/>
  22.     </content>
  23.  
  24.     <implementation>
  25.  
  26. <!-- FIXME: instantiate this._log for all objects -->
  27.  
  28.       <constructor><![CDATA[
  29.         const Cc = Components.classes;
  30.         const Ci = Components.interfaces;
  31.         const Cr = Components.results;
  32.         const Cu = Components.utils;
  33.  
  34.         Cu.import("resource://weave/ext/Observers.js");
  35.         Cu.import("resource://weave/notifications.js");
  36.         Cu.import("resource://weave/service.js");
  37.  
  38.     Observers.add("weave:notification:added", this.onNotificationAdded, this);
  39.     Observers.add("weave:notification:removed", this.onNotificationRemoved, this);
  40.  
  41.         for each (var notification in Notifications.notifications)
  42.           this._appendNotification(notification);
  43.       ]]></constructor>
  44.  
  45.       <destructor><![CDATA[
  46.         Observers.remove("weave:notification:added", this.onNotificationAdded, this);
  47.         Observers.remove("weave:notification:removed", this.onNotificationRemoved, this);
  48.       ]]></destructor>
  49.  
  50.       <method name="onNotificationAdded">
  51.         <parameter name="subject"/>
  52.         <parameter name="data"/>
  53.         <body><![CDATA[
  54.           this._appendNotification(subject);
  55.         ]]></body>
  56.       </method>
  57.  
  58.       <method name="onNotificationRemoved">
  59.         <parameter name="subject"/>
  60.         <parameter name="data"/>
  61.         <body><![CDATA[
  62.           // If the view of the notification hasn't been removed yet, remove it.
  63.           var notifications = this.allNotifications;
  64.           for each (var notification in notifications) {
  65.             if (notification.notification == subject) {
  66.               notification.close();
  67.               break;
  68.             }
  69.           }
  70.  
  71.           // If the user has just closed the last notification, close the panel.
  72.           // FIXME: this is not quite right, because it might not have been
  73.           // the user that caused weave:notification:removed to get called.
  74.           // We need to differentiate between "notification removed" and "user
  75.           // closed the notification" and only close the panel if it was
  76.           // the user who closed the last notification.  Maybe we should make
  77.           // the notification's close method handle closing the panel,
  78.           // but should the notification box or its notifications really know
  79.           // they are located inside the panel?
  80.           var panel = document.getElementById("sync-notifications-panel");
  81.           if (panel.state == "open" &&
  82.             Notifications.notifications.length == 0)
  83.             panel.hidePopup();
  84.         ]]></body>
  85.       </method>
  86.  
  87.       <method name="_appendNotification">
  88.         <parameter name="notification"/>
  89.         <body><![CDATA[
  90.           var node = this.appendNotification(notification.title,
  91.                                              notification.description,
  92.                                              notification.iconURL,
  93.                                              notification.priority,
  94.                                              notification.buttons);
  95.           node.className = notification.constructor.name;
  96.           node.notification = notification;
  97.         ]]></body>
  98.       </method>
  99.  
  100.     </implementation>
  101.   </binding>
  102.  
  103.   <binding id="notification" extends="chrome://global/content/bindings/notification.xml#notification">
  104.     <content>
  105.       <xul:hbox class="notification-inner outset" flex="1" xbl:inherits="type" align="start">
  106.         <xul:image anonid="messageImage" class="messageImage" xbl:inherits="src=image" style="padding: 3px;"/>
  107.         <xul:vbox flex="1">
  108.           <xul:hbox anonid="details" align="center" flex="1">
  109.             <xul:description anonid="messageText" class="messageText" flex="1" xbl:inherits="xbl:text=label"/>
  110.             <xul:spacer flex="1"/>
  111.           </xul:hbox>
  112.           <xul:description xbl:inherits="xbl:text=value"/>
  113.  
  114.           <!-- The children are the buttons defined by the notification. -->
  115.           <xul:hbox oncommand="document.getBindingParent(this)._doButtonCommand(event);">
  116.             <xul:spacer flex="1"/>
  117.             <children/>
  118.           </xul:hbox>
  119.  
  120.         </xul:vbox>
  121.         <xul:spacer flex="1"/>
  122.         <xul:toolbarbutton ondblclick="event.stopPropagation();"
  123.                            class="messageCloseButton tabbable"
  124.                            xbl:inherits="hidden=hideclose"
  125.                            tooltiptext="&closeNotification.tooltip;"
  126.                            oncommand="document.getBindingParent(this).close()"/>
  127.       </xul:hbox>
  128.     </content>
  129.     <implementation>
  130.       <!-- Note: this used to be a field, but for some reason it kept getting
  131.          - reset to its default value for TabNotification elements.
  132.          - As a property, that doesn't happen, even though the property stores
  133.          - its value in a JS property |_notification| that is not defined
  134.          - in XBL as a field or property.  Maybe this is wrong, but it works.
  135.          -->
  136.       <property name="notification"
  137.                 onget="return this._notification"
  138.                 onset="this._notification = val; return val;"/>
  139.       <method name="close">
  140.         <body><![CDATA[
  141.           Notifications.remove(this.notification);
  142.  
  143.           // We should be able to call the base class's close method here
  144.           // to remove the notification element from the notification box,
  145.           // but we can't because of bug 373652, so instead we copied its code
  146.           // and execute it below.
  147.           var control = this.control;
  148.           if (control)
  149.             control.removeNotification(this);
  150.           else
  151.             this.hidden = true;
  152.         ]]></body>
  153.       </method>
  154.     </implementation>
  155.   </binding>
  156.  
  157. </bindings>
  158.